﻿// (c)2010 David Schwarz (david.schwarz@live.com)
// This file is licensed under GNU GPL v2 license, see more at http://www.gnu.org/licenses/gpl-2.0.html
namespace Z2.Core
{

	#region Using

	using System.Collections.Generic;

	#endregion

	/// <summary>
	/// Třída reprezentující herní sektor
	/// </summary>
	internal class WorldSector
	{

		#region Const

		public const int SIZE = 512;
		
		#endregion

		#region Members

		private List<ObjectBase> m_objects;
		
		#endregion

		#region Constructor

		/// <summary>
		/// Konstruktor
		/// </summary>
		public WorldSector()
		{
		}

		#endregion

		#region Properties

		/// <summary>
		/// Vrací seznam objektů, které jsou zaregistrované v tomto sektoru
		/// </summary>
		public List<ObjectBase> Objects
		{
			get
			{
				return this.m_objects;
			}
		}

		#endregion

		#region Methods

		/// <summary>
		/// Metoda odregistruje objekt <paramref name="obj"/>
		/// </summary>
		/// <param name="obj"><see cref="ObjectBase"/></param>
		public void Unregister(ObjectBase obj)
		{
			if (this.m_objects == null)
			{
				return;
			}
			if (this.m_objects.Contains(obj))
			{
				this.m_objects.Remove(obj);
			}
		}

		/// <summary>
		/// Metoda zaregistruje objekt <paramref name="obj"/>
		/// </summary>
		/// <param name="obj"><see cref="ObjectBase"/></param>
		public void Register(ObjectBase obj)
		{
			if (obj.Sector == this)  // Nemá smysl se sem registrovat, když tu už jsme
			{
				return;
			}
			if (this.m_objects == null)
			{
				this.m_objects = new List<ObjectBase>();
			}

			if (obj.Sector != null)
			{
				obj.Sector.Unregister(obj);
			}

			obj.Sector = this;
			this.m_objects.Add(obj);
		}

		#endregion

	}
}
